import { InjectModel } from '@nestjs/mongoose';
import { Injectable } from '@nestjs/common';

@Injectable()
export class RoleService {
    constructor(@InjectModel('Role') private readonly roleModel) {}

    async find(where = {}, fields = null) {
        try {
            return await this.roleModel.find(where, fields);
        } catch {
            return [];
        }
    }
    async create(roleInfo) {
        try {
            return await this.roleModel.create(roleInfo);
        } catch (error) {
            return null;
        }
    }
    async update(roleInfo) {
        try {
            return await this.roleModel.updateOne({ _id: roleInfo._id }, roleInfo);
        } catch (error) {
            return null;
        }
    }
    async delete(roleInfo) {
        try {
            return await this.roleModel.deleteOne(roleInfo);
        } catch (error) {
            return null;
        }
    }
}
